//
//  MerchantsTableViewController.m
//  ksjv2
//
//  Created by mac on 14/12/22.
//  Copyright (c) 2014年 CnbizMedia. All rights reserved.
//

#import "MerchantsTableViewController.h"
#import "Util.h"
#import "PageControlScrollView.h"
#import "MerchantsListViewController.h"
#import "MerchantsViewController.h"
#import "ClubeShowTableViewController.h"
@interface MerchantsTableViewController ()<PageScrollDelegate,EGORefreshTableHeaderDelegate,UIScrollViewDelegate>{
    PageControlScrollView*Pscroll;
    BOOL isLoading;//是否在刷新

    int _page;
    NSMutableArray*userData;
    NSMutableArray*topData;

    NSMutableArray* topArray;
    NSArray*headerButtonData;
    BOOL reloading;
    NSMutableArray *buttonPhotoArray;
    NSMutableArray *buttonNameArray;
    
}
@property (weak, nonatomic) IBOutlet UIView *headerBview;
@property(nonatomic,strong)EGORefreshTableHeaderView * refreshHeaderView;



@end

@implementation MerchantsTableViewController
@synthesize refreshHeaderView=_refreshHeaderView;

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UserDefaults setObject:@"center" forKey:@"center"];//刷新在中间
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"俱乐部";
    [SVProgressHUD show];
    
    UIImageView *headBackImage = [[UIImageView alloc]init];
    
    [UserDefaults setObject:@"center" forKey:@"center"];//刷新在中间

     
    NSString *iphoneTheHight = [UserDefaults objectForKey:@"iphoneTheHight"];
    if ([iphoneTheHight isEqualToString:@"iphone5"]) {
        [headBackImage sd_setImageWithURL:[UserDefaults objectForKey:@"headBack_NewYear5"] ];
        
    }
    if ([iphoneTheHight isEqualToString:@"iphone6"]) {
        [headBackImage sd_setImageWithURL:[UserDefaults objectForKey:@"headBack_NewYear6"] ];
    }
    if ([iphoneTheHight isEqualToString:@"iphone6p"]) {
        [headBackImage sd_setImageWithURL:[UserDefaults objectForKey:@"headBack_NewYear6p"] ];
    }
    
//    [self.navigationController.navigationBar setBackgroundImage:headBackImage.image forBarMetrics:UIBarMetricsDefault];

    
    
    //判断是不是要放置新春版
    NSString *newOldYear = [UserDefaults objectForKey:@"NewYear" ];
    if ([newOldYear isEqualToString:@"NewYear"]) {
         NSString *iphoneTheHight = [UserDefaults objectForKey:@"iphoneTheHight"];
        if ([iphoneTheHight isEqualToString:@"iphone5"]) {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"headBack_NewYear5"] forBarMetrics:UIBarMetricsDefault];
        }
        if ([iphoneTheHight isEqualToString:@"iphone6"]) {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"headBack_NewYear6"] forBarMetrics:UIBarMetricsDefault];
        }
        if ([iphoneTheHight isEqualToString:@"iphone6p"]) {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"headBack_NewYear6p"] forBarMetrics:UIBarMetricsDefault];
        }
    
        //系统字体颜色
//        [self.navigationController.navigationBar setTitleTextAttributes:
        
//         @{NSFontAttributeName:[UIFont systemFontOfSize:17],
        
//           NSForegroundColorAttributeName:[UIColor colorWithRed:[[UserDefaults objectForKey:@"fontcolor1"] integerValue] green:[[UserDefaults objectForKey:@"fontcolor2"] integerValue] blue:[[UserDefaults objectForKey:@"fontcolor3"] integerValue] alpha:1]}];

        [self.navigationController.navigationBar setTitleTextAttributes:
         
         @{NSFontAttributeName:[UIFont systemFontOfSize:17],
           
           NSForegroundColorAttributeName:[UIColor whiteColor]}];

    }
    
    [UserDefaults setInteger:0 forKey:@"hiddenInt"];//是否隐藏头图的文字介绍 0隐藏，1显示
    
    
    
    buttonPhotoArray = [[NSMutableArray alloc]init];
    buttonNameArray = [[NSMutableArray alloc]init];
    buttonNameArray = [NSMutableArray arrayWithObjects:@"论坛",@"游学",@"咨询",@"创投",nil];
//    buttonPhotoArray = [NSMutableArray arrayWithObjects:@"luntan",@"youxue",@"咨询",@"chuangtou",nil];
    buttonPhotoArray = [NSMutableArray arrayWithObjects:@"clubBBS",@"clubStudyTour",@"clubConsulting",@"clubVenture",nil];
    
    
//    _headerBview.backgroundColor = UIColorFromRGBWithAlpha(0xFF00aa, 0.2f);
    
    self.tableView.backgroundColor=UIColorFromRGB(0xf5f5f5);
    self.tableView.tableHeaderView.backgroundColor=UIColorFromRGB(0xf5f5f5);
//    self.tableView.tableHeaderView.backgroundColor=[UIColor greenColor];
//    self.tableView.backgroundColor=[UIColor redColor];
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;

    EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(self.tableView.frame.origin.x,self.tableView.frame.origin.y, self.tableView.frame.size.width, 0)];
    view.delegate = self;
    [self.tableView addSubview:view];
    
 
    
    _page=1;
    self.refreshHeaderView = view;
    [self initPscroll];
//    [self initHeaderButtons];
    [self initFourButton];
    [self loadNews];
    
    [[AppAPIClient sharedClient] GET:@"Jiameng/Category" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *result = responseObject[@"data"];
        if([result isKindOfClass:[NSNull class]] || [result count] == 0){
            return;
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
    //接收通知的设置,接收各种目标在设置的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showBootomBar) name:@"showBootomBar" object:nil];//都是nil

}

- (void)showBootomBar{

    self.hidesBottomBarWhenPushed = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)loadNews{
    if(isLoading){
    [SVProgressHUD dismiss];
    return;
    }
    
    isLoading = YES;
    NSDictionary*parameter;
    if (_page==1) {
        parameter=@{@"p":[NSString stringWithFormat:@"%d",_page],@"top":@"1",@"ps":@"20"};
    }else{
        parameter=@{@"p":[NSString stringWithFormat:@"%d",_page],@"ps":@"20"};
    }

    NSLog(@"_page -==--==--==--==- %d",_page);
//    Jiameng/Item
    [[AppAPIClient sharedClient] GET:@"Club/List" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *result = responseObject[@"data"];
        NSLog(@"result --- %@",result);
        if([result isKindOfClass:[NSNull class]] || [result count] == 0||[result[@"content"] count]==0){
            return;
        }
        if(userData == nil){
            userData = [[NSMutableArray alloc]initWithArray:result[@"content"] copyItems:YES];
        }else{
            NSMutableArray *newResult = [[NSMutableArray alloc]initWithArray:userData];
            [newResult addObjectsFromArray:result[@"content"]];
            userData = [[NSMutableArray alloc]initWithArray:newResult copyItems:YES];
        }
        
        _page++;
        if (topArray.count==0) {
            topArray=[[NSMutableArray alloc]initWithArray:responseObject[@"data"][@"top"] copyItems:YES];
            NSMutableArray*array=[[NSMutableArray alloc]init];
            for (NSDictionary*dic in topArray) {
                PageImageView*view=[[PageImageView alloc]init];
                view.backgroundColor = [UIColor clearColor];
                view.All_Dic=dic;
                view.ID=dic[@"id"];
                view.PCatid=dic[@"catid"];
                view.imageUrl=dic[@"thumb"];
                view.PTitle=dic[@"title"];
                view.URL=dic[@"url"];
                
                [array addObject:view];
            }
            [Pscroll refresh:array];
            isLoading = NO;
        }
        
        if (userData.count < 20){
        isLoading = YES;
        }
        
        reloading = NO;
        [self.tableView reloadData];
        [SVProgressHUD dismiss];
        [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"ERR: %@",operation.responseString);
        [SVProgressHUD dismiss];
        isLoading = YES;
    }];
}

-(void)initFourButton{

    float x = self.view.frame.size.width/4;
    float y = 177;
    if (self.view.frame.size.width>320) {
        y+=55;
        
    }
    float row = 1;
    float i = 0;
        for (long int j=0;j<4;j++){
 
            i++;
            if (row==5) {
                y+=85;
                row=1;
            }
            UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
            //                    [button setBackgroundColor:[UIColor purpleColor]];
            [button setFrame:CGRectMake(x*row-60-((x-60)/2), y, 60, 70)];
            NSString *photoName = buttonPhotoArray[j];
            NSLog(@"photoName == %@",photoName);
            [button setImage:[UIImage imageNamed:photoName] forState:UIControlStateNormal];
            
            
            
            [button setImageEdgeInsets:UIEdgeInsetsMake(-20, 7.5, 0, 0)];
            
            //给button设置title
            [button setTitle:buttonNameArray[j] forState:UIControlStateNormal];
            NSLog(@"buttonNameArray[j]=%@",buttonNameArray[j]);
            [button setTitleEdgeInsets:UIEdgeInsetsMake(55, -45, 0, 0)];
            NSDictionary *attribs = @{NSFontAttributeName: [UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor blackColor]};
            NSMutableAttributedString *attributedText =[[NSMutableAttributedString alloc] initWithString:buttonNameArray[j] attributes:attribs];
            NSLog(@"attributedText = %@",attributedText);
            [button setAttributedTitle:attributedText forState:UIControlStateNormal];
            [button setTag:j];
            [button addTarget:self action:@selector(mPm:) forControlEvents:UIControlEventTouchUpInside];
            [self.tableView.tableHeaderView addSubview:button];
            
            
            row++;
        }

}

-(void)initHeaderButtons{
    
    [[AppAPIClient sharedClient] GET:@"Jiameng/Category" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //        [SVProgressHUD dismiss];
        
        if([responseObject isKindOfClass:[NSNull class]] || [responseObject count] == 0){
            return;
        }
        float x = self.view.frame.size.width/4;
        float y = 177;
        if (self.view.frame.size.width>320) {
            y+=55;
            
        }
        float row = 1;
        float i = 0;
        headerButtonData=responseObject[@"data"];
        for (long int j=0;j<4;j++){
            NSDictionary*dic=headerButtonData[j];
            if ([dic[@"description"] length]>5&&i<8) {
                i++;
                if (row==5) {
                    y+=85;
                    row=1;
                }
            UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
//                    [button setBackgroundColor:[UIColor purpleColor]];
            [button setFrame:CGRectMake(x*row-60-((x-60)/2), y, 60, 70)];
                NSString *photoName = buttonPhotoArray[j];
                NSLog(@"photoName == %@",photoName);
            [button setImage:[UIImage imageNamed:photoName] forState:UIControlStateNormal];
                
                
//            [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:dic[@"description"]] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//            } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
////                [button setImage:[CommonHelper reSizeImage:image toSize:CGSizeMake(45, 45)] forState:UIControlStateNormal];
//                [button setImage:image forState:UIControlStateNormal];
//            }];
//                NSLog(@"++++++%@",dic);
                
                
                
            [button setImageEdgeInsets:UIEdgeInsetsMake(-20, 7.5, 0, 0)];
                
                //给button设置title
            [button setTitle:buttonNameArray[j] forState:UIControlStateNormal];
                NSLog(@"buttonNameArray[j]=%@",buttonNameArray[j]);
            [button setTitleEdgeInsets:UIEdgeInsetsMake(55, -45, 0, 0)];
            NSDictionary *attribs = @{NSFontAttributeName: [UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor blackColor]};
            NSMutableAttributedString *attributedText =[[NSMutableAttributedString alloc] initWithString:buttonNameArray[j] attributes:attribs];
                NSLog(@"attributedText = %@",attributedText);
            [button setAttributedTitle:attributedText forState:UIControlStateNormal];
            [button setTag:j];
            [button addTarget:self action:@selector(mPm:) forControlEvents:UIControlEventTouchUpInside];
            [self.tableView.tableHeaderView addSubview:button];
                

            row++;
            }
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"ERR: %@",operation.responseString);
        
    }];

}
-(void)viewDidLayoutSubviews{
}
-(void)initPscroll{
    
    NSMutableArray*array=[[NSMutableArray alloc]init];
    for (int i=0;i<5;i++) {
        PageImageView*view=[[PageImageView alloc]init];
        view.ID=@"";
        view.PCatid=@"";
        view.URL=@"11";
        view.PTitle=@"";
        
        [array addObject:view];
    }
    float h = 165;
    if (self.view.frame.size.width>320) {
        h+=55;
        CGRect frame = self.tableView.tableHeaderView.frame;
        
        self.tableView.tableHeaderView.frame=CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height-40);//h+55 按钮的view的高度
        NSLog(@"self.tableView.tableHeaderView.frame == %@",self.tableView.tableHeaderView.frame);
        
    }
    
    else {
    
        CGRect frame = self.tableView.tableHeaderView.frame;
        NSLog(@"frame == %@",frame);
        self.tableView.tableHeaderView.frame=CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height-90);//h+55 按钮的view的高度
    }
    
    Pscroll = [[PageControlScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, h) pictures:array whichView:@"club"];
//    Pscroll.p
    
    Pscroll.delegate = self;
    
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
    singleTap.cancelsTouchesInView = NO;
    [Pscroll addGestureRecognizer:singleTap];
    
//    UIImageView
    
    [self.tableView.tableHeaderView addSubview:Pscroll];
    //    [view addSubview:baffle];
    
}
- (void)mPm:(id)sender {
    UIButton*button=(UIButton*)sender;

    NSLog(@"button.tag == %ld",(long)button.tag);
    NSInteger buttonTag = button.tag;
    NSLog(@"buttonTag == %ld",(long)buttonTag);
    
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setInteger:buttonTag forKey:@"buttonTagNumber"];
    [userDefault synchronize];//存入文件
    
    
    
//    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setInteger:0 forKey:@"underBarShow"];
    [userDefault synchronize];//存入文件
//    [self performSegueWithIdentifier:@"mPm" sender:button];  //ClubeShow
//    [self performSegueWithIdentifier:@"ClubeShow" sender:button];
//    ClubeShowTableViewController *clubeShowTableViewController = [[ClubeShowTableViewController alloc]init];
    if (button.tag == 2) {
        
        
        [UserDefaults setObject:@"clube" forKey:@"whereComeForm"];
        self.hidesBottomBarWhenPushed = YES;
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController *MainCell=[story instantiateViewControllerWithIdentifier:@"ZhiXunViewController"];
        [self.navigationController pushViewController:MainCell animated:YES];

    }
    
    else {
        
        [UserDefaults setObject:@"clube" forKey:@"whereComeForm"];
        self.hidesBottomBarWhenPushed = YES;
    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    LoginViewController *MainCell=[story instantiateViewControllerWithIdentifier:@"ClubeShowTableViewController"];
    [self.navigationController pushViewController:MainCell animated:YES];
    }
//    UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:clubeShowTableViewController];
//    [self presentViewController:nav animated:YES completion:nil];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

   
    UIViewController *destination = segue.destinationViewController;
    if([destination isKindOfClass:[MerchantsListViewController class]]){
         UIButton*button=(UIButton*)sender;
        [destination setValue:headerButtonData[button.tag][@"cateid"] forKey:@"Source"];
        [destination setTitle:headerButtonData[button.tag][@"name"]];
    }else if([destination isKindOfClass:[MerchantsViewController class]]){
        if ([sender isKindOfClass:[NSDictionary class]]) {
            [destination setValue:sender forKey:@"Merchants_Dic"];
            return;
        }
        long int index=[sender intValue];
        [destination setValue:userData[index] forKey:@"Merchants_Dic"];
    }
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return userData.count;
}
//-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//    return @"热门赚钱项目推荐";
//}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 158;
//    75;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 15)];
    UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(5, 5, 200, 21)];
    label.font=[UIFont systemFontOfSize:15];
    label.text=@"热门赚钱项目推荐";
    [view addSubview:label];
    view.backgroundColor=UIColorFromRGB(0xf5f5f5);
    
    return view;
//    return NO;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bigImageCell" forIndexPath:indexPath];
    //bigImageCell
    if (cell==nil) {
        cell=[tableView dequeueReusableCellWithIdentifier:@"bigImageCell"];
    }
    NSDictionary*dic=userData[indexPath.row];
    
    
    if(indexPath.row == [userData count]-2){
        [SVProgressHUD showWithStatus:@"数据加载中..." maskType:SVProgressHUDMaskTypeClear];
        [self loadNews];
    }
   
    
    UIImageView*imageview=(UIImageView*)[cell.contentView viewWithTag:11];
    [imageview sd_setImageWithURL:[NSURL URLWithString:dic[@"thumb"]]];
    UILabel*name=(UILabel*)[cell.contentView viewWithTag:22];
    name.text=dic[@"title"];

//    UILabel*xmtzje=(UILabel*)[cell.contentView viewWithTag:44];
//    NSString *str = [dic[@"xmtzje"] stringByReplacingOccurrencesOfString:@"," withString:@"~~"];
//    xmtzje.text= [NSString stringWithFormat:@"%@浏览",[dic objectForKey:@"hit"] ];
//    [NSString stringWithFormat:@"￥%@万",str];
    UILabel*comment=(UILabel*)[cell.contentView viewWithTag:55];
    comment.text=[NSString stringWithFormat:@"%@",dic[@"comment"]];
    cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
    
    NSString *timeString = [dic objectForKey:@"inputtime"];
    NSLog(@"timeString -- %@",timeString);
    //得到运动时间，需要转成年月日
    NSString *formatString = @"yyyy.MM.dd";
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:formatString];
    NSDate*confromTimesp = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)[timeString intValue] - 28800];
    NSString *dateString =[NSString stringWithFormat:@"%@",[dateFormat stringFromDate:confromTimesp] ];
    NSLog(@"date: %@", dateString);
    UILabel*timeLabel=(UILabel*)[cell.contentView viewWithTag:13];
    timeLabel.text = dateString;
    
    UILabel*description=(UILabel*)[cell.contentView viewWithTag:33];
    description.text=dateString;
    
    return cell;
}

- (void)pushToTheNextView{


    
    self.hidesBottomBarWhenPushed = YES;
    [UserDefaults setObject:@"clube" forKey:@"whereComeForm"];
    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    LoginViewController *MainCell=[story instantiateViewControllerWithIdentifier:@"OneClubeViewController"];
    [self.navigationController pushViewController:MainCell animated:YES];
    
    //    [self performSegueWithIdentifier:@"merchants" sender:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   [tableView deselectRowAtIndexPath:indexPath animated:NO];//点击后不会有阴影
    
    NSDictionary *buttonDic = userData[indexPath.row];
    NSString *catid = [buttonDic objectForKey:@"catid"];

    //将相应的数据先保存
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setInteger:1 forKey:@"underBarShow"];
    [userDefault synchronize];//存入文件
    
    //    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:buttonDic forKey:@"lunTanDic"];
    [userDefault synchronize];//存入文件
    
    
    if ([catid isEqualToString:@"3671"] ) {
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault setInteger:0 forKey:@"buttonTagNumber"];
        [userDefault synchronize];//存入文件
        
    }
    
    else if ( [catid isEqualToString:@"3674"]) {
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault setInteger:1 forKey:@"buttonTagNumber"];
        [userDefault synchronize];//存入文件
        
    }
    
    else if ([catid isEqualToString:@"3672"]) {
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault setInteger:3 forKey:@"buttonTagNumber"];
        [userDefault synchronize];//存入文件
        
    }
    //将相应的数据先保存
    
    
    NSString *auth_type = [buttonDic objectForKey:@"auth_type"];
    BOOL auth_typeBOOL;
    
    
    if([auth_type rangeOfString:@"1"].location !=NSNotFound)//_roaldSearchText
    {
        NSLog(@"yes");
    
        if (auth_type.length > 0) {
            
            NSArray *auth_typeArray = [auth_type componentsSeparatedByString:@","]; //从字符A中分隔成2个元素的数组
            NSLog(@"auth_typeArray:%@",auth_typeArray);
            NSString *groupids_view = [buttonDic objectForKey:@"groupids_view"];
            NSString *a = [[NSString alloc] init];
            for (a in auth_typeArray) {
                NSLog(@"--a-- %@",a);
                if ([a isEqualToString:groupids_view]) {
                    [self pushToTheNextView];
                    return;
                    auth_typeBOOL = NO;
                }
            }
            
             [SVProgressHUD showSuccessWithStatus:@"您没有阅读权限。"];
        }
    }
    else
    {
        [self pushToTheNextView];
        NSLog(@"no");
    }
    
    
    
    
    
    
}
#pragma mark - PageControlScrollViewDelegate

//UIScrollView响应gesture的action
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
    
    
}

-(void)pageScrollDelegate:(PageControlScrollView*)pageScrollView didSelectindex:(int)index{
    
    NSLog(@"index ==- %d",index);
    
//    topArray.count =  _pageControl.numberOfPages;
}

//点击头图进行跳转界面
-(void)pageScrollDelegate:(PageControlScrollView *)pageScrollView didScrollImageView:(PageImageView*)imageview{
    
    
    if (topArray.count > 0) {
//    [self performSegueWithIdentifier:@"merchants" sender:imageview.All_Dic];
    NSLog(@"pageScrollView == %@",pageScrollView);
    NSLog(@"imageview == %@",imageview);
//    NSArray *abc = [NSArray arrayWithObjects:pageScrollView.gestureRecognizers, nil];
    NSLog(@"");
//    art._Dict=imageview.All_Dic;
    
    NSDictionary *pushDic = imageview.All_Dic;
        NSDictionary *okDic   = [[NSDictionary alloc] initWithObjectsAndKeys:@"catid",pushDic[@"catid"], @"id",pushDic[@"id"], @"thumb",pushDic[@"thumb"], @"title",pushDic[@"title"], nil];
        
        
    NSLog(@"pushDic -- %@",pushDic);
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    //    [userDefault setInteger:0 forKey:@"buttonTagNumber"];
    //    [userDefault synchronize];//存入文件
    
    [userDefault setObject:pushDic forKey:@"lunTanDic"];
    [userDefault synchronize];//存入文件
    NSString *catid = [pushDic objectForKey:@"catid"];
    
       
        [userDefault setInteger:1 forKey:@"underBarShow"];
        [userDefault synchronize];//存入文件
    
    if ([catid isEqualToString:@"3671"] ) {
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault setInteger:0 forKey:@"buttonTagNumber"];
        [userDefault synchronize];//存入文件
        
    }
    
    else if ( [catid isEqualToString:@"3674"]) {
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault setInteger:1 forKey:@"buttonTagNumber"];
        [userDefault synchronize];//存入文件
        
    }
    
    else if ([catid isEqualToString:@"3672"]) {
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault setInteger:3 forKey:@"buttonTagNumber"];
        [userDefault synchronize];//存入文件
        
    }
    
//    self.hidesBottomBarWhenPushed = YES;
//    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//    LoginViewController *MainCell=[story instantiateViewControllerWithIdentifier:@"OneClubeViewController"];
//    [self.navigationController pushViewController:MainCell animated:YES];

        
        NSString *auth_type = [pushDic objectForKey:@"auth_type"];
        BOOL auth_typeBOOL;
        
        
        if([auth_type rangeOfString:@"1"].location !=NSNotFound)//_roaldSearchText
        {
            NSLog(@"yes");
            
            if (auth_type.length > 0) {
                
                NSArray *auth_typeArray = [auth_type componentsSeparatedByString:@","]; //从字符A中分隔成2个元素的数组
                NSLog(@"auth_typeArray:%@",auth_typeArray);
                NSString *groupids_view = [pushDic objectForKey:@"groupids_view"];
                NSString *a = [[NSString alloc] init];
                for (a in auth_typeArray) {
                    NSLog(@"--a-- %@",a);
                    if ([a isEqualToString:groupids_view]) {
                        [self pushToTheNextView];
                        return;
                        auth_typeBOOL = NO;
                    }
                }
                
                [SVProgressHUD showSuccessWithStatus:@"您没有阅读权限。"];
            }
        }
        else
        {
            [self pushToTheNextView];
            NSLog(@"no");
        }

        
    }

}
#pragma mark - UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    
    int page = (scrollView.contentOffset.x / scrollView.bounds.size.width);
    NSLog(@"page = %d",page);
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    
    [self.refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    
}
#pragma mark RefreshHeaderViewDelegate Methods

-(void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view{
    if(reloading){
        return;
    }
    reloading=YES;
    [self performSelector:@selector(doneLoadingViewData) withObject:nil afterDelay:0];
}
- (void)doneLoadingViewData{
    
    //  model should call this when its done loading
    _page=1;
    isLoading = NO;
    userData = nil;
    topArray = [[NSMutableArray alloc]init];
    [self loadNews];
    
}
-(BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView *)view{
    return reloading;
}
-(NSDate *)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView *)view{
    return [NSDate date];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
